﻿#ifndef PST_MAINWINDOW_H
#define PST_MAINWINDOW_H

#include <QMainWindow>

#include "ElaWindow.h"
#include "ElaToolButton.h"
#include "PostEnumType.h"
#include "parser/JsonDef.h"

class ElaContentDialog;
class QStandardItem;
class vtkXMLUnstructuredGridReader;

namespace pst
{
    class QTextReader;
    class TextFileParser;
    class CenterWidget;
    class SelectDatatDialog;
    class IWidgetSignal;
    class NearFieldDataGenerator;



    struct FileInfo
    {
        QString m_filePath;
        QString m_fileName;
        FileDataTypes m_fileType;
    };
    class MainWindow : public ElaWindow
    {
        Q_OBJECT

    public:
        MainWindow(QWidget* parent = nullptr);
        ~MainWindow();

        inline void setInputDir(const QString& dir) { m_inputDir = dir; }
        inline QString getInputDir() const { return m_inputDir; }
        inline void setOutputDir(const QString& dir) { m_outputDir = dir; }
        inline QString getOutputDir() const { return m_outputDir; }
        inline void setSimuType(const QString& type) { m_simuType = type; }
        inline QString getSimuType() const { return m_simuType; }

        /// @brief 将hirf2D的数据格式转换为标准格式
        void changeHirf2DDataFormat(const QString& inputFilePath, const QString& outputFilePath);
    private slots:
        void slot_toolBtnClick();
        void importJingDianData();
        void slot_exportBtnClick();
        void importHirf2DData();
        void importJingDian3DAs2D();
        void slot_importProjectData(const QStringList& filepathList = QStringList());
        void slot_read3DData(const QString& filepath = QString());
        void slot_checkGraphType(const QList<QStandardItem*>& index);
        void slot_displayNew2DGraph();
        void slot_displayNew3DGraph();
        void slot_displayNewSurfaceGraph();
        void slot_saveGraphToLocal();
        // 选完数据后，开始打开图画线
        void slot_sendSelectedInfo(int& variableIndex,
            QList<QPair<int, QList<int>>>& chosenData, QList<int>& valueIndexs);


        void slot_sendQuestionMessageToUI(int& result, const QString& title, const QString& message);
        void slot_sendErrorMessageToUI(const QString& message);
        void slot_addToCurrentGraph(const QList<QStandardItem*>& index);
    private:
        void initWindow();
        void initToolBar();
        void initStatusBar();
        /// @brief 初始化中心视图，左侧工程树及右侧的结果查看视图
        void initContentWidget();
        void checkFileType(const QList<FileDataTypes>& inputType, bool& is2D, bool& isPolar, bool& is3D);
        void ShowSelecetDataDialog();

        void initConnections();
        bool readerDelimitedTextFromLocal(const QString& fileName);
    private:
        /// @brief 软件关闭弹窗
        ElaContentDialog* _closeDialog{ nullptr };
        /// @brief 中心视图
        CenterWidget* m_centerWidget{ nullptr };

        //QHash<QString, QString > m_fileType; //记录文件类型，用于检测可用于显示哪些图
        QHash<QStandardItem*, ResultDataPointer > m_fileType; //记录文件类型，用于检测可用于显示哪些图
        QTextReader* m_textReader;
        TextFileParser* m_textFileParser;

        ElaToolButton* m_toolButton3DGraph{ nullptr };
        ElaToolButton* m_toolButton2DGraph{ nullptr };
        ElaToolButton* m_toolButtonPolarGraph{ nullptr };
        ElaToolButton* m_toolButtonSurfaceGraph{ nullptr };
        ElaToolButton* m_toolButtonSaveImageToLocal{ nullptr };

        QList<QStandardItem*> m_currentChosenFiles;

        QString m_inputDir{ QDir::homePath() };
        QString m_outputDir{ QDir::homePath() };
        QString m_simuType{};
        int m_screenShotNum{ 0 };

        SelectDatatDialog* m_selecetDataDialog; //点击曲线类型后开始选数据，选完数据再画图
        QList<QString> m_optionalKeyList;
        QList<QString> m_errorMessageList;
        QList<ResultDataPointer> m_selectFileList;
        QHash<QStandardItem*, vtkXMLUnstructuredGridReader*> m_vtuReader{};//（包括.vtu、.pvtu、.pvtp等

        IWidgetSignal* m_signalInstance;
        bool m_openNewWindow{ true };

        vtkSmartPointer<vtkDelimitedTextReader> m_delimitedTextReader;
        NearFieldDataGenerator* m_nearFieldDataGenerator;
    };
}

#endif // PST_MAINWINDOW1_H
